package ooday04;

public class Test {
    public static void main(String[] args) {
        //Anima a = new Anima();//抽象类不能被实例化
        //1)多态的第一个特点
        Anima[] animas = new Anima[5];
        animas[0] = new Dog("小黑",6,"黑");
        animas[1] = new Dog("小黄",4,"黄");
        animas[2] = new Fish("黄花",8,"黄");
        animas[3] = new Fish("金枪",12,"白");
        animas[4] = new Chick("蛋蛋",4,"红");
        for(int i =0;i<animas.length;i++){
            System.out.println(animas[i].name);
            animas[i].eat();
            animas[i].drink();

            if (animas[i] instanceof Dog){
                Dog dog = (Dog)animas[i];
                dog.lookHome();
            }

            if(animas[i] instanceof Chick){
                Chick chick = (Chick)animas[i];
                chick.layEgggs();
            }
            if(animas[i] instanceof Swim){
                Swim s = (Swim)animas[i];
                s.Swim();
            }
        }
        /*
        //2)多态的第二个特点
        Master master = new Master();
        Dog dog = new Dog("小黑,",4,"黑");
        Fish fish = new Fish("小金",6,"金");
        Chick chicks = new Chick("红红",2,"红");
        master.feed(dog);//在传参的同时向上造型
        master.feed(fish);
        master.feed(chicks);
         */
    }
}
